package com.pinyougou.shop.controller;


import com.alibaba.dubbo.config.annotation.Reference;
import com.pinyougou.pojo.Seller;
import com.pinyougou.service.SellerService;
import org.springframework.security.crypto.bcrypt.BCrypt;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;


//@ResponseBody将Java对象转换成json格式
//@ResponseBody+@Controller
@RestController
@RequestMapping("/seller")
public class SellerController {


    @Reference(timeout = 10000)
    private SellerService sellerService;

    /**
     * 添加商家
     * @param seller
     * @return
     */
    @PostMapping("/save")
    public boolean save(@RequestBody Seller seller){

        try {
            /** 密码加密*/
            BCryptPasswordEncoder bCryptPasswordEncoder =new BCryptPasswordEncoder();
            String password = bCryptPasswordEncoder.encode(seller.getPassword());
            seller.setPassword(password);
            sellerService.save(seller);
            return true;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;

    }

}
